package com.eastfair.projectcore.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.eastfair.core.base.entity.Entity;
import java.time.LocalDate;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.eastfair.core.base.entity.SuperEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import static com.eastfair.core.utils.DateUtils.DEFAULT_DATE_TIME_FORMAT;
import com.eastfair.annotation.model.EchoVO;

import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;

/**
 * <p>
 * 实体类
 * DB WorkerID Assigner for UID Generator
 * </p>
 *
 * @author ligang
 * @since 2023-09-08
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("worker_node")
@ApiModel(value = "WorkerNode", description = "DB WorkerID Assigner for UID Generator")
@AllArgsConstructor
public class WorkerNode extends Entity<Long> implements EchoVO {

    private static final long serialVersionUID = 1L;
    @TableField(exist = false)
    private Map<String, Object> echoMap = new HashMap<>();

    @TableId(
            value = "id",
            type = IdType.AUTO
    )
    @ApiModelProperty("主键")
    @NotNull(
            message = "id不能为空",
            groups = {SuperEntity.Update.class}
    )
    protected Long id;


    /**
     * host name
     */
    @ApiModelProperty(value = "host name")
    @NotEmpty(message = "请填写host name")
    @Size(max = 64, message = "host name长度不能超过64")
    @TableField(value = "HOST_NAME", condition = LIKE)
    @Excel(name = "host name")
    private String hostName;

    /**
     * port
     */
    @ApiModelProperty(value = "port")
    @NotEmpty(message = "请填写port")
    @Size(max = 64, message = "port长度不能超过64")
    @TableField(value = "PORT", condition = LIKE)
    @Excel(name = "port")
    private String port;

    /**
     * node type: ACTUAL or CONTAINER
     */
    @ApiModelProperty(value = "node type: ACTUAL or CONTAINER")
    @NotNull(message = "请填写node type: ACTUAL or CONTAINER")
    @TableField(value = "TYPE")
    @Excel(name = "node type: ACTUAL or CONTAINER")
    private Integer type;

    /**
     * launch date
     */
    @ApiModelProperty(value = "launch date")
    @NotNull(message = "请填写launch date")
    @TableField(value = "LAUNCH_DATE")
    @Excel(name = "launch date", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDate launchDate;

    /**
     * modified time
     */
    @ApiModelProperty(value = "modified time")
    @NotNull(message = "请填写modified time")
    @TableField(value = "MODIFIED")
    @Excel(name = "modified time", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime modified;

    /**
     * created time
     */
    @ApiModelProperty(value = "created time")
    @NotNull(message = "请填写created time")
    @TableField(value = "CREATED")
    @Excel(name = "created time", format = DEFAULT_DATE_TIME_FORMAT, width = 20)
    private LocalDateTime created;


    @Builder
    public WorkerNode(Long id, 
                    String hostName, String port, Integer type, LocalDate launchDate, LocalDateTime modified, LocalDateTime created) {
        this.id = id;
        this.hostName = hostName;
        this.port = port;
        this.type = type;
        this.launchDate = launchDate;
        this.modified = modified;
        this.created = created;
    }

}
